// JavaScript Document
// id 分页元素id；totalPage 总页数；currIndex 当前页码；pagePrefix 文件前缀；pageSuffix 文件后缀；totalCount 总记录数
function createPageHTML(id, totalPage, currIndex, pagePrefix, pageSuffix, totalCount) {
    if (totalCount == 0) {
        return;
    }
    var homePageText = '', prevPageText = '', pageIndexText = '', nextPageText = '', endPageText = '', totalPageText = '', totalCountText = '', pageJumpText = '', param;
    homePageText = '<li class="home_page"><a href="' + pagePrefix + '.' + pageSuffix + '">首页</a></li>';
    param = totalPage == 1 ? '' : '_' + totalPage;
    endPageText = '<li class="end_page"><a href="' + pagePrefix + param + '.' + pageSuffix + '">尾页</a></li>';
    var firstPage = 1, lastPage = totalPage;
    if (totalPage > 5) {
        if (currIndex <= 2) {
            lastPage = 5;
        } else if ((totalPage - currIndex) <= 2) {
            firstPage = totalPage - 4;
        } else {
            firstPage = currIndex - 2;
            lastPage = currIndex + 2;
        }
    }
    for (var i = firstPage; i <= lastPage; i++) {
        param = i == 1 ? '' : '_' + i;
        var currrent = i == currIndex ? ' class="current"' : '';
        pageIndexText += '<li class="page_index"><a href="' + pagePrefix + param + '.' + pageSuffix + '"' + currrent + '">' + i + '</a></li>';
    }
    param = (currIndex - 1) == 1 ? '' : '_' + (currIndex - 1);
    prevPageText = '<li class="prev_page"><a href="' + pagePrefix + param + '.' + pageSuffix + '">上一页</a></li>';
    nextPageText = '<li class="prev_page"><a href="' + pagePrefix + '_' + (currIndex + 1) + '.' + pageSuffix + '">下一页</a></li>';
    if (totalPage == 1) {
        prevPageText = '<li class="prev_page"><span>上一页</span></li>';
        nextPageText = '<li class="prev_page"><span>下一页</span></li>';
    } else if (currIndex == 1) {
        prevPageText = '<li class="prev_page"><span>上一页</span></li>';
    } else if (currIndex == totalPage) {
        nextPageText = '<li class="prev_page"><span>下一页</span></li>';
    }
    totalCountText = '<li class="total_count"><span>共' + totalCount + '条记录</span></li>';
    var pageJumpFun = "pageJump('" + pagePrefix + "','" + pageSuffix + "'," + totalPage + ")";
    pageJumpText = '<li class="page_jump">跳转至<input id="page_input" type="text" onkeypress="if (event.keyCode == 13){' + pageJumpFun + '}">页<a href="javascript:;" onclick="' + pageJumpFun + '">确定</a></li>';
    document.getElementById(id).innerHTML = totalPageText + totalCountText + homePageText + prevPageText + pageIndexText + nextPageText + endPageText + pageJumpText;
}
function pageJump(pagePrefix, pageSuffix, totalPage) {
    var pageIndex = document.getElementById('page_input').value.replace(" ", '');
    if (parseInt(pageIndex) > 0 && parseInt(pageIndex) <= totalPage) {
        var param = pageIndex == 1 ? '' : '_' + pageIndex;
        window.location.href = pagePrefix + param + '.' + pageSuffix;
    }
}